using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Cmn;
using EntLibEC.Info.Basic;
using EntLibEC.Biz.Basic;
using EntLibEC.Biz;

namespace EntLibEC.View.Cmn
{
	/// <summary>
	/// Summary description for ManufacturerPickUp.
	/// </summary>
	public partial class ManufacturerPickUp : PageBase
	{

		protected string bodyOnLoad;
		private string clientID;

		protected EntLibEC.View.Cmn.BiStatus ucStatus;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if ( !Page.IsPostBack)
			{
				ucStatus.BindStatus(true);
                ucStatus.StatusSysNo = Convert.ToInt32(AppEnum.BiStatus.Valid);
			}

			if ( Request.QueryString["clientID"] != null )
			{
				clientID = Request.QueryString["clientID"].ToString();
			}

			if ( Request.QueryString["Sysno"] != null )
			{
				int sysno = Convert.ToInt32(Request.QueryString["Sysno"].ToString());
				ManufacturerInfo oInfo = ManufacturerManager.GetInstance().Load(sysno);
				bodyOnLoad = "javascript:window.opener.document.all['" + this.clientID + ":txtManuName'].value='" + oInfo.ManufacturerName + "';";
				bodyOnLoad += "window.opener.document.all['" + this.clientID + ":txtManuSysNo'].value='" + oInfo.SysNo + "';";
				bodyOnLoad += "window.close(); return false;";
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void btnSearch_Click(object sender, System.EventArgs e)
		{
			if ( txtManuName.Text.Trim() == "" && ucStatus.StatusSysNo == AppConst.IntNull)
			{
				Assert(lblMessage, "please fill in something.", -1);
				return;
			}

			Hashtable ht = new Hashtable(2);
			if ( txtManuName.Text.Trim() != "" )
				ht.Add("ManufacturerName",txtManuName.Text.Trim());
			if ( ucStatus.StatusSysNo != AppConst.IntNull )
				ht.Add("Status", ucStatus.StatusSysNo );

			DataSet ds = ManufacturerManager.GetInstance().GetManuDs(ht);
			DataGrid1.DataSource = ConvertDs(ds);
			DataGrid1.DataBind();
			int rows = 0;
			if ( Util.HasMoreRow(ds) )
				rows = ds.Tables[0].Rows.Count;
			Assert(lblMessage, "Records:" + rows.ToString(), 1);
		}


		private DataSet ConvertDs(DataSet ds)
		{
			if ( !Util.HasMoreRow(ds) )
				return ds;
			foreach(DataRow dr in ds.Tables[0].Rows)
			{
				dr["ManufacturerName"] = "<a href='ManufacturerPickUp.aspx?Sysno=" + dr["Sysno"].ToString() +"&clientID=" + this.clientID + "'>" + dr["ManufacturerName"].ToString() + "</a>";
			}
			return ds;
		}
	}
}
